package org.hncors.gnssparse.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.Log;
import android.widget.Toast;

import org.hncors.gnssparse.MainActivity;
import org.hncors.gnssparse.model.LocationItemData;
import org.xutils.BuildConfig;
import org.xutils.x;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;


public class MyApplication extends Application {
private final String TAG = "Application";
	public SharedPreferences mSharedPreferences = null;
	/** 默认城市 */

	public static MyApplication app;
    private MainActivity main;
    private int mainIndex = -1;
    public static Context context;
    private List<Activity> mList = new LinkedList<>();
    private List<Activity> oList = new LinkedList<>();
    public ArrayList<LocationItemData> mSateItemsDataArray = new ArrayList<LocationItemData>();
    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        Configuration config=new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
        return res;
    }
	@Override
	public void onCreate() {
		super.onCreate();
        app = this;
        context = getApplicationContext();
        x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能.
		mSharedPreferences = getSharedPreferences("car_path2", Context.MODE_PRIVATE);
		initLoginParams();
	}


    public static MyApplication getInstance(){
        return app;
    }
	/**
	 * 上次登录参数
	 */
	private void initLoginParams() {

	}


	@Override
	public void onTerminate() {
		super.onTerminate();
	}
    // add Activity
    public void addActivity(Activity activity) {
        mList.add(activity);
    }

    public MainActivity getMain() {
        return main;
    }

    public void setMain(MainActivity main) {
        this.main = main;
    }

    // add Activity
    public void addActivityMore(Activity activity) {
        oList.add(activity);
    }

    public void exitToMain() {
        try {
            for (Activity activity : oList) {
                if (activity != null)
                    activity.finish();
            }
            oList.clear();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exit() {
        try {
            for (Activity activity : mList) {
                if (activity != null)
                    activity.finish();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.exit(0);
        }
    }

    public int getMainIndex() {
        return mainIndex;
    }

    public void setMainIndex(int mainIndex) {
        this.mainIndex = mainIndex;
    }

    public void initCoolRefreshView() {


    }
}
